const session = require("express-session"),
      mongoStore = require("connect-mongo")(session),
      config = require("./index");

const initSession = function(app){
  const sessionConfig = {
  	secret: "GHD_PORTAL_123!@#",
  	resave: true,
  	rolling: true,
  	saveUninitialized: false,
  	cookie: {
  		maxAge: 3600000 * 2
  	},
    store: new mongoStore({
      url: config.db.url,
      port: 27017
    })
  };
  app.use(session(sessionConfig));
}

module.exports = initSession;
